{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "59fa725c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "125265\n",
      "87442\n",
      "87377\n",
      "427Hz\n",
      "88150.77678\n",
      "88150.776787\n",
      "88150.779709\n",
      "88150.779759\n",
      "88150.787485\n",
      "88150.78757999999\n",
      "88150.7894805\n",
      "88150.7935835\n",
      "88150.7956825\n",
      "88150.79840649999\n",
      "88150.80114\n",
      "88150.80297349999\n",
      "88150.8046305\n",
      "88150.80726949999\n",
      "88150.8097485\n",
      "88150.81287299999\n",
      "88150.814136\n",
      "88150.8159975\n",
      "88150.818051\n",
      "88150.821819\n"
     ]
    }
   ],
   "source": [
    "import csv\n",
    "\n",
    "with open(\"gaze.csv\", \"r\") as f:\n",
    "    reader = csv.reader(f)\n",
    "    rows = [row for row in reader]\n",
    "print(len(rows))\n",
    "time_data = [i[0] for i in rows]\n",
    "time_data.pop(0)\n",
    "\n",
    "\n",
    "\n",
    "ans = []\n",
    "for i in range(len(rows)):\n",
    "    if i == 0:\n",
    "        continue\n",
    "    elif float(rows[i][2]) > 0.9:\n",
    "        ans.append(rows[i])\n",
    "        # print(rows[i])\n",
    "    else:\n",
    "        continue\n",
    "\n",
    "# 3, 4 mean\n",
    "mean_x = 0\n",
    "mean_y = 0\n",
    "for i in ans:\n",
    "    mean_x += float(i[3])\n",
    "for j in ans:\n",
    "    mean_y += float(j[4])\n",
    "mean_x /= len(ans)\n",
    "mean_y /= len(ans)\n",
    "mean = (mean_x ** 2 + mean_y ** 2) ** (1/2)\n",
    "\n",
    "# print(mean_y,mean_x)\n",
    "print(len(ans))\n",
    "sigma_x = 0\n",
    "sigma_y = 0\n",
    "for i in ans:\n",
    "    sigma_x += (float(i[3]) - mean_x) ** 2\n",
    "for j in ans:\n",
    "    sigma_y += (float(j[4]) - mean_y) ** 2\n",
    "sigma_x = sigma_x / len(ans)\n",
    "sigma_y = sigma_y / len(ans)\n",
    "sigma = (sigma_x + sigma_y) ** (1/2)\n",
    "\n",
    "\n",
    "i = 0\n",
    "while i < len(ans):\n",
    "    if mean - 3 * sigma < ((float(ans[i][3])) ** 2 + (float(ans[i][4])) ** 2) ** (1/2) < mean + 3 * sigma:\n",
    "        i += 1\n",
    "    else:\n",
    "        ans.pop(i)\n",
    "print(len(ans))\n",
    "\n",
    "\n",
    "for i in ans:\n",
    "    time_stack = []\n",
    "    day = float(i[0]) % 86400\n",
    "    time_stack.append(int(float(i[0]) // 86400))\n",
    "    hour = day % 3600\n",
    "    time_stack.append(int(day // 3600))\n",
    "    time_stack.append(int(hour // 60 ))\n",
    "    minute = hour % 60\n",
    "    time_stack.append(minute)\n",
    "    i[0] = '1970-01-0' + str(2 + time_stack[0]) + 'T' + ':'.join([str(i) for i in time_stack[1:]]) + '+0000'\n",
    "\n",
    "data = rows.copy()\n",
    "data.pop(0)\n",
    "\n",
    "print(str(int(len(data)//(float(88443.7055739999) - float(data[0][0])))) + \"Hz\")\n",
    "\n",
    "time = int(float(time_data[0]) * 100)\n",
    "place_stack = [0]\n",
    "for i in range(1, len(time_data)):\n",
    "    if int(float(time_data[i][0]) * 100) == time + 1:\n",
    "        time += 1\n",
    "        place_stack.append(i)\n",
    "for i in range(20):\n",
    "    print(time_data[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "823b6fff",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
